//
//  RecoardHisCell.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/20.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "RecoardHisCell.h"
#import "ShowNumView.h"
@interface RecoardHisCell ()
{
    __weak IBOutlet UIImageView *img;
    __weak IBOutlet UILabel *titleLab;
    __weak IBOutlet UILabel *numLab;
    __weak IBOutlet UILabel *timeLab;
    __weak IBOutlet UILabel *canyuLab;
    __weak IBOutlet UIButton *buyBtn;
    __weak IBOutlet UIButton *showBtn;
    
    RecordHisModel *_currentModel;
}
@end
@implementation RecoardHisCell

- (void)awakeFromNib {
    // Initialization code
    [self addSubview:[WYPublic getFenGexian:0 :self.frame.size.height-0.5 :WYMWITH :0.5]];
    buyBtn.layer.masksToBounds = YES;
    buyBtn.layer.cornerRadius = 2;
    buyBtn.backgroundColor = QBB_RED_COLOR;
    buyBtn.hidden = YES;
    
    
}
- (void)fillCellWithModel:(RecordHisModel *)model
{
    _currentModel = model;
    [img sd_setImageWithURL:[NSURL URLWithString:model.his_record_imgPath] placeholderImage:[UIImage imageNamed:@"moren"]];
    titleLab.text = [NSString stringWithFormat:@"(第%@期)%@",model.his_record_qishu,model.his_record_title];
    numLab.text = [NSString stringWithFormat:@"订单编号:%@",model.his_record_code];
    timeLab.text = [NSString stringWithFormat:@"下单时间:%@",model.his_record_time];
    canyuLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"参与次数:" Middle:model.his_record_gonumber RightStr:@"次" Font:14];
    if ( model.isGoOnFlag) {
        if(model.isMineFlag){
            [buyBtn setTitle:@"追加" forState:UIControlStateNormal];
        }else{
            [buyBtn setTitle:@"跟买" forState:UIControlStateNormal];
        }
        buyBtn.hidden = NO;
        showBtn.hidden = YES;
    }else{
        buyBtn.hidden = YES;
        showBtn.hidden = NO;
    }
    NSString *show_shopping = [[NSUserDefaults standardUserDefaults] valueForKey:@"show_shopping"];
    [buyBtn setHidden:YES];
    if (show_shopping.integerValue == 1) {
        [buyBtn setHidden:NO];
    }

    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
//查看夺宝号
- (IBAction)showbtnOnclick:(id)sender {
    ShowNumView *his = [[ShowNumView alloc]initWithArr:_currentModel.his_record_nums AndQiShu:_currentModel.his_record_qishu AndTitle:_currentModel.his_record_title];
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    [window addSubview:his];
}

- (IBAction)buyBtnOnClick:(id)sender {
    

    WYShopCarModel *car_model = [[WYShopCarModel alloc]init];
    //期数
    car_model.qishu = [WYPublic getUsefullStr:_currentModel.his_record_qishu];
    car_model.car_id = [WYPublic getUsefullStr:_currentModel.his_record_id];
    car_model.car_new_id = [WYPublic getUsefullStr:_currentModel.his_record_sid ];
    car_model.imgPath = [WYPublic getUsefullStr:_currentModel.his_record_imgPath];
    car_model.name = [WYPublic getUsefullStr:_currentModel.his_record_title];
    car_model.all_need = [WYPublic getUsefullStr:_currentModel.his_record_moneycount];
    car_model.left_need = [WYPublic getUsefullStr:_currentModel.his_record_gonumber];
    //加入购物车
    if(car_model != nil){
        if ([[WYDataBase sharedDataBase]insertPdcToCarWithModel:car_model]) {
            NSInteger index = 2;
            NSString *show_shopping = [[NSUserDefaults standardUserDefaults] valueForKey:@"show_shopping"];
            if (show_shopping.integerValue == 1) {
                //显示
                index = 3;
            }
            [[WYMainTabBarVC shareMainTaBarVC] changeSelectedWithIndex:index];
            [[WYMainTabBarVC shareMainTaBarVC]updateCountToCar];
            [[WYMainTabBarVC shareMainTaBarVC].navigationController popToRootViewControllerAnimated:YES];
        }
        
    }
}
@end
